home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / HideMenuBar.c < prev    next >
Text File  |  1995-07-26  |  4KB  |  150 lines

  1. /*
  2. HideMenuBar.c
  3.  
  4. Based on:
  5.  
  6. "Code gadgets: Hiding the menu bar", THINKin' CaP, 1(2):28-29, Fall 1990.
  7. Copyright © 1991 SPLAsh Resources.
  8.  
  9. and
  10.  
  11. Symantec THINK Reference 2, "How to Hide the MenuBar".
  12.  
  13. HISTORY:
  14. 2/28/91 dgp added to VideoToolbox
  15. 8/24/91    dgp    Made compatible with THINK C 5.
  16. 1/25/93 dgp removed obsolete support for THINK C 4.
  17. 1/25/93    dgp Replaced SysEqu.h by LoMem.h and changed program accordingly.
  18. 2/23/93    dgp    Call CopyQuickDrawGlobals to make sure qd is valid.
  19. 2/27/93    dgp Edited the code and comments, partly copying from THINK Reference's
  20.             suggestion for how to do this. This was prompted by David Brainard's
  21.             report that these routines were crashing when called within the
  22.             MATLAB environment. The main changes are to also call
  23.             CalcVisBehind() after restoring, and to use DiffRgn
  24.             to restore by cutting the menu bar back out of the desktop
  25.             instead of restoring by copying from a saved copy of the region. 
  26. 3/3/93    dgp    Added SquareCorners and RestoreCorners, with support for 1-bit quickdraw.
  27. 10/8/94    dgp    Made compatible with Apple's new Universal Headers and PowerPC.
  28. */
  29. #include "VideoToolbox.h"
  30. //#include <Menus.h>
  31. #if UNIVERSAL_HEADERS
  32.     #include <LowMem.h>
  33.     #if UNIVERSAL_HEADERS>1
  34.         #define WindowPeek WindowRef
  35.     #endif
  36. #else
  37.     #define LMGetMBarHeight() (* (short *) 0x0BAA)
  38.     #define LMSetMBarHeight(MBarHeightValue) ((* (short *) 0x0BAA) = (MBarHeightValue))
  39. #endif
  40. static short oldMBarHeight;                    // Pixel height of the menu bar
  41. static RgnHandle mBarRgn=NULL;                // Region encompassing the menu bar
  42. static RgnHandle cornerRgn[MAX_SCREENS];
  43.  
  44. void HideMenuBar(void)
  45. {
  46.     Rect r;
  47.     
  48.     if (LMGetMBarHeight()>0) {
  49.         mBarRgn=NewRgn();
  50.         CopyQuickDrawGlobals();                // Make sure qd is valid
  51.         r=qd.screenBits.bounds;
  52.         r.bottom=r.top+LMGetMBarHeight();
  53.         RectRgn(mBarRgn,&r);
  54.         oldMBarHeight=LMGetMBarHeight();
  55.         LMSetMBarHeight(0);
  56.         UnionRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  57.         PaintOne(NULL,mBarRgn);
  58.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  59.     }
  60. }
  61.  
  62. void ShowMenuBar(void)
  63. {
  64.     if(LMGetMBarHeight()==0 && mBarRgn!=NULL){
  65.         LMSetMBarHeight(oldMBarHeight);
  66.         DiffRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  67.         DrawMenuBar();
  68.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  69.         DisposeRgn(mBarRgn);
  70.         mBarRgn=NULL;
  71.     }
  72. }
  73.  
  74. void SquareCorners(GDHandle device)
  75. // Extend GrayRgn to include this screen's corners, which otherwise might be rounded off.
  76. // If device==NULL then applies to all screens.
  77. {
  78.     int i;
  79.     Rect r;
  80.     long quickDraw;
  81.     
  82.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  83.     if(quickDraw<gestalt8BitQD){
  84.         i=0;
  85.         CopyQuickDrawGlobals();                // Make sure qd is valid
  86.         r=qd.screenBits.bounds;
  87.         r.top+=LMGetMBarHeight();
  88.     }else{
  89.         if(device==NULL){
  90.             for(i=0;GetScreenDevice(i)!=NULL;i++)SquareCorners(GetScreenDevice(i));
  91.             return;
  92.         }
  93.         i=GetScreenIndex(device);
  94.         if(i>=MAX_SCREENS)return;
  95.         r=(*device)->gdRect;
  96.         if(device==GetMainDevice())r.top+=LMGetMBarHeight();
  97.     }
  98.     cornerRgn[i]=NewRgn();
  99.     RectRgn(cornerRgn[i],&r);
  100.     DiffRgn(cornerRgn[i],GetGrayRgn(),cornerRgn[i]);
  101.     if(EmptyRgn(cornerRgn[i]))return;
  102.     UnionRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  103.     PaintBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  104.     CalcVisBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  105. }
  106.  
  107. void RestoreCorners(GDHandle device)
  108. // Restore rounding to this screen.
  109. // If NULL then applies to all screens.
  110. {
  111.     int i;
  112.     long quickDraw;
  113.     
  114.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  115.     if(quickDraw<gestalt8BitQD){
  116.         i=0;
  117.     }else{
  118.         if(device==NULL){
  119.             for(i=0;GetScreenDevice(i)!=NULL;i++)RestoreCorners(GetScreenDevice(i));
  120.             return;
  121.         }
  122.         i=GetScreenIndex(device);
  123.         if(i>=MAX_SCREENS)return;
  124.     }
  125.     if(cornerRgn[i]!=NULL){
  126. //        CopyQuickDrawGlobals();            // Make sure qd is valid.
  127. //        FillRgn(cornerRgn[i],(ConstPatternParam)&qd.black);    // don't know what port it belongs to
  128.         DiffRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  129.         DisposeRgn(cornerRgn[i]);
  130.         cornerRgn[i]=NULL;
  131.     }
  132. }
  133.  
  134. void UnclipScreen(GDHandle device)
  135. {
  136.     long quickDraw;
  137.  
  138.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  139.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())HideMenuBar();
  140.     SquareCorners(device);
  141. }
  142.  
  143. void RestoreScreenClipping(GDHandle device)
  144. {
  145.     long quickDraw;
  146.  
  147.     RestoreCorners(device);
  148.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  149.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())ShowMenuBar();
  150. }